import * as service from '../services';

let indexs = {};
let index = 1;

export default {
  namespace: 'node',
  state: {
    list: [],
  },
  reducers: {
    save(state, { payload: { data }}) {
      data.received_time = Date.now();
      if (!indexs[data.node_name]) {
        indexs[data.node_name] = index++;
      }
      let list = [...state.list];
      list[indexs[data.node_name] - 1] = data;
      return { ...state, list };
    },
    reset() {
      indexs = {};
      index = 1;
      return {
        list: [],
      }
    }
  },
}
